<?php
/**
 * Created by PhpStorm.
 * User: lelouchms
 * Date: 2019/6/3
 * Time: 10:46
 */

namespace app\index\controller;


use app\common\exception\CustomerException;

/**
 * 房屋委托
 * Class Entrust
 * @package app\index\controller
 */
class Entrust extends Base
{

    public function initialize()
    {
        $this->allow_action = ['save'];
        parent::initialize();
    }

    /**
     * 新增房屋委托
     * @throws CustomerException
     */
    public function save()
    {
        $requestData = $this->request->only(['area_id', 'username', 'phone', 'house_name', 'remark']);
        $validate = new \app\common\validate\Entrust();
        $checkFlag = $validate->scene("add")->check($requestData);
        if (!$checkFlag) throw new CustomerException($validate->getError());
        $flag = (new \app\common\model\Entrust())->save($requestData);
        if (!$flag) throw new CustomerException("委托失败,请稍后重试");
        return "委托成功";
    }


}